<template>
    <h3>添加借款信息</h3>
    <table border="1">
        <tr>
            <td>借款名称</td>
            <td>
                <input type="text" v-model="info.LoadName">
            </td>
        </tr>
        <tr>
            <td>借款最高金额</td>
            <td>
                <input type="text" v-model="info.LoadMaxPrice">
            </td>
        </tr>
        <tr>
            <td>借款年限</td>
            <td>
                <input type="text" v-model="info.LoadYear">
            </td>
        </tr>
        <tr
>
            <td>利息</td>
            <td>
              <!-- 下拉框绑定利息 -->
                <select v-model="info.IId">
                    <option value="">请选择</option>
                    <option v-for="item in Sinfo" :value="item.IId">{{item.IYear}}年{{item.IName}}%</option>
                 
                </select>



            </td>
        </tr>
        <tr>
            <td>借款简介</td>
            <td>
                <input type="text" v-model="info.LoadAb">
            </td>
        </tr>
        <tr>
            <td>借款时间</td>
            <td>
                <input type="date" v-model="info.LoadDate">
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button" value="添加" @click="add()">

            </td>
           
        </tr>

    </table>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios';
import { useRouter } from 'vue-router';

const router=useRouter()

const Sinfo=ref([
    {
        IId:"",
        IName:'',
        IYear:'',
    }
    ])

const info=ref({
    LoadName:'',
    LoadMaxPrice:'',
    LoadYear:'',
    IId:'',
    LoadAb:'',
    LoadDate:'',
})

onMounted(()=>{
    Bang()
})

const Bang=()=>{
    axios.get('http://localhost:2134/api/Loan/Bang')
    .then(res=>{
        Sinfo.value=res.data
    })
}

const add=()=>{
    axios.post('http://localhost:2134/api/Loan/AddLoan',{
        LoadName:info.value.LoadName,
        LoadMaxPrice:info.value.LoadMaxPrice,
        LoadYear:info.value.LoadYear,
        IId:info.value.IId,
        LoadAb:info.value.LoadAb,
        LoadDate:info.value.LoadDate,
    }).then(res=>{
       if(res.data>0){
        console.log(res.data)
            alert('添加成功')
        //   router.push({

        //     path:'/ShowLoan',
        //     query:{
        //         LoadId:res.data[0].LoadId
        //     }
        //   })
        location.href="/ShowLoan"
       }
       else{

            alert('添加失败')
       }
    })
}
</script>